package com.david.dubbo.router;

import org.apache.curator.RetryPolicy;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.retry.ExponentialBackoffRetry;

/**
 * @author David
 * @version V1.0
 * @Package com.david.dubbo.router
 * @date 2021/4/24 15:44
 */
public class ZookeeperClients {

    private final CuratorFramework client;
    private static ZookeeperClients intance;
    static {
        //重试机制
        RetryPolicy retryPolicy=new ExponentialBackoffRetry(1000,3);
        CuratorFramework curatorFramework = CuratorFrameworkFactory.newClient("192.168.219.102:2181",
                3000, 15000, retryPolicy);
        intance=new ZookeeperClients(curatorFramework);
    }
    private ZookeeperClients(CuratorFramework client) {
        this.client = client;
        //启动客户端
        client.start();
    }

    public static ZookeeperClients getInstance(){
        return intance;
    }

    public  static  CuratorFramework client(){
        return  intance.client;
    }

}
